<template>
  <div class="search-history">
    <van-cell title="搜索历史">
      <div v-if="isDeleteShow">
        <span @click="$emit('clearHistories')">全部删除 </span>

        <span @click="isDeleteShow = false">完成</span>
      </div>
      <van-icon v-else name="delete" @click="isDeleteShow = true" />
    </van-cell>
    <van-cell
      v-for="(text, ind) in searchHistory"
      :key="ind"
      :title="text"
      @click="onSearchItemClick(text, ind)"
    >
      <van-icon name="close" v-show="isDeleteShow" />
    </van-cell>
  </div>
</template>

<script>
export default {
  name: 'SearchHistory',
  components: {},
  props: {
    searchHistory: {
      type: Array,
      required: true
    }
  },
  data () {
    return {
      isDeleteShow: false
    }
  },
  computed: {},
  watch: {},
  created () {},
  mounted () {},
  methods: {
    onSearchItemClick (text, ind) {
      // 判断是否在编辑状态
      if (this.isDeleteShow) {
        this.searchHistory.splice(ind, 1)
      } else {
        this.$emit('search', text)
      }
    }
  }
}
</script>

<style scoped lang="less"></style>
